//
//  ClaimPicTableViewCell.m
//  MemberProject
//
//  Created by mac on 15/7/17.
//  Copyright (c) 2015年 MAC OS X. All rights reserved.
//

#import "ClaimPicTableViewCell.h"
@implementation ClaimPicTableViewCell

- (void)awakeFromNib {
    self.collection.backgroundColor=[UIColor clearColor];
    self.collection.dataSource=self;
    self.collection.delegate=self;
    
    [self.collection registerNib:[UINib nibWithNibName:@"ClaimPicCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"CellIdentifier"];
    
//    self.arrM=[NSMutableArray array];
//    [self.arrM addObjectsFromArray:@[];
}

- (IBAction)chickAddButton:(id)sender {
    if([self.delegate respondsToSelector:@selector(chickAddButtonWithCell:)]){
        [self.delegate chickAddButtonWithCell:self];
    }
    
}

#pragma mark - collection delegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.arrM.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier=@"CellIdentifier";
    ClaimPicCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    cell.imageView.image=self.arrM[indexPath.row];
    cell.delegate=self;
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    UIImage *image=self.arrM[indexPath.row];
    if([self.delegate respondsToSelector:@selector(didSelectImage:)]){
        [self.delegate didSelectImage:image];
    }
}

-(void)longGestureWithCell:(ClaimPicCollectionViewCell *)cell{
    NSIndexPath *indexPath=[self.collection indexPathForCell:cell];
    [self.arrM removeObjectAtIndex:indexPath.row];
    [self.collection deleteItemsAtIndexPaths:@[indexPath]];
    
}

#pragma mark - about image
-(void)addImage:(UIImage *)image{
    [self.arrM addObject:image];
    [self.collection insertItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:self.arrM.count-1 inSection:0]]];
    [self.collection scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:self.arrM.count-1 inSection:0] atScrollPosition:UICollectionViewScrollPositionRight animated:YES];
}
@end
